<!doctype html>
<html>
<head>
<meta charset="utf-8">
</head>
		<!--basic styles-->
		<link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/chosen.css" />
		<link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/datepicker.css" />            
<body>
<?php $this->load->view('vheader')?>  
<br/>
<?php // Change the css classes to suit your needs  
  
$attributes = array('name' => 'form_po','onSubmit' => 'return validate(this)','id' => 'f_submit');
echo form_open('pembelian/purchasing_order/Simpan_DataPo',$attributes);

?>

<?php 
 $tgl			= date("d-m-Y");

if(!empty($nopo)){	
	//$message = $_SESSION['idtx'].'--'.$_SESSION['userlogin'];
	/*
	echo "<script type='text/javascript'>alert('$nopo');</script>";	
	*/
	 $jns_pemasok	= "1";
	 $prod 			= "";
	 $supplier_id	= "";	 
	 $supplier		= "";	 
	 $tot_po		= 0 ;
	 $kena_ppn		= "0";
	 $disc_rp		= 0;	 
	 $netto			= 0;
	 $disc			= 0;
}
else
{
 $prod			= isset($prod);; 	
 $nama_produk	= isset($nama_produk);
 $qty 			= isset($qty);
 $hrg			= isset($hrg);
 $satuan		= isset($satuan);
 $disc			= isset($disc);
 $total			= isset($total);
 $supplier_id	= isset($supplier_id);
 $supplier		= isset($supplier);
 $nama			= isset($nama);
 $alamat		= isset($alamat);
 $kdpos			= isset($kdpos);
 $notelp		= isset($notelp);
 $fax			= isset($fax);
 $npwp			= isset($fax);
 	
 $prod			= "";
 $nama_produk	= "";
 $qty 			= 0;
 $hrg			= 0;
 $satuan		= "";
 $netto			= 0;
 $disc			= 0;
 $disc_rp		= 0;
 $total			= 0;
 
 $total_qty		= 0;
 $tot_po		= 0;
 $total_netto	= 0;
 $total_disc	= 0;
 $total_disc_rp	= 0;
 $tot_netto_ppn	= 0;
 $nopo			= "";
 
 $nama			= "";
 $alamat		= "";
 $kota			= "";
 $kdpos			= "";
 $notelp		= "";
 $fax			= "";
 $npwp			= "";
 $hp			= "";
 $cp			= "";
 $web			= "";
 $email			= "";
 $jns_pemasok	= "1";
 $kena_ppn 		= 0;
 
	}

?>
<div class="widget-box">
    <div class="widget-header">
        <h3 style="text-align:center; font-weight:bolder">Purchasing Order</h3>       
    </div>

    <div class="widget-body">
    <div class="widget-main">   
    <br/>     
    <table width="1400px" style="border:0px solid #666;" border="0px">
      <tr >
        <td width="140">
            <label for="no_po">No. Purchasing Order </label>
        </td>
        <td>	  
            <input style="width:180px" id="no_po" type="text" name="no_po" maxlength="10" value="<?php echo $nopo; ?>"  readonly />
            <span class="required" style="color:#F00">*</span>
        </td>
        <td width="20">&nbsp;</td>
        <td colspan="3" style="text-align:right">
            <label for="tgl_po">Tanggal PO &nbsp;</label>
        </td>
        <td style="text-align:right">
            <input class="date-picker" id="tgl_po" name="tgl_po" type="text" data-date-format="dd-mm-yyyy" value="<?php echo $tgl ;?>" />
        </td>
      </tr>
      <tr>
        <td width="140">
            <label for="jns_pemasok">Jenis Pemasok</label>
        </td>
        <td colspan="2">
            <input id="jns_pemasok" name="jns_pemasok" type="radio" onClick=""  value="1" <?php if($jns_pemasok == '1') echo "checked";?> 
             <label for="jns_pemasok" >Supplier</label>&nbsp;
            <input id="jns_pemasok" name="jns_pemasok" type="radio" onClick="removeOptions(document.getElementById("mySelectObject"));"  value="2" <?php if($jns_pemasok == '2') echo "checked";?> 
             <label for="jns_pemasok" >Pabrik</label>&nbsp;
            
            <input style="margin:0px 0px 0px 105px" type="button" value="Buat Supplier Baru">    	
        </td>
        <td colspan="2">&nbsp;</td>
        <td style="width:2%">&nbsp;</td>
        <td width="6%">&nbsp;</td>
      </tr>
      <tr>
        <td width="140"><label for="nm_supplier">Nama Supplier</label></td>
        <td colspan="2">
            <input type="hidden" name="supplier_id" value="<?php echo $supplier_id;?>"/>
            <input type="text" class="input-xlarge" name="nama_supplier" id="nama_supplier" placeholder="Pilih Supplier" 
            value="<?php echo $supplier?>"/>	        
    <!-- 
            <select onChange="getData(this)" style="width:200px" class="chzn-select" id="nama_supplier" name="nama_supplier" data-placeholder="Pilih Data Hasil Pencarian">
                <option value=""/>           
                <?php
    
                foreach($fetch_supplier as $row)
                {  
                    if ($jns_pemasok == $row->jns_pemasok){
                        echo '<option value="'.$row->kode.'">'.$row->nama.'</option>';                
                    }else{
                        echo '<option value="'.$row->kode.'">'.$row->nama.'</option>';                
                    }
                    
                   
                }
                ?>            
                
            </select>
    -->        
            <span class="required" style="color:#F00">*</span>
        </td>
        <td style="width:110px">
            <label for="nm_cp">Contact Person</label>
        </td>
        <td>
            <input style="width:230px" id="nm_cp" type="text" name="nm_cp"/>
        	<span class="required" style="color:#F00">*</span></td>
        <td>
              <label for="no_hp">Hp</label>
        </td>
        <td>
            <input id="no_hp" type="text" name="no_hp"  value="<?php echo set_value('no_hp'); ?>"  />
        </td>
      </tr>
      <tr>
        <td width="140" rowspan="2">
            <label for="alamat">Alamat<br><br><br></label>
        </td>
        <td rowspan="2">
          <?php echo form_textarea( array( 'name' => 'alamat', 'rows' => '2', 'cols' => '44', 'readonly'  => 'readonly') )?>
        </td>
        <td rowspan="2">&nbsp;</td>
        <td><label for="email">Email</label></td>
        <td colspan="3"><input style="width:230px" id="email" type="text" name="email" readonly value="<?php echo set_value('email'); ?>"  /></td>
      </tr>
      <tr>
        <td><label for="web">Web</label></td>
        <td colspan="3">
            <input style="width:230px" id="web" type="text" name="web" readonly value=""<?php echo set_value('web'); ?>
        </td>
      </tr>
      <tr>
        <td width="140"><label for="kota">Kota</label></td>
        <td width="19%">
            <input style="width:60.6%" id="kota" type="text" name="kota" readonly  value=""  />&nbsp;&nbsp;
            <label for="kd_pos">Kode Pos</label>&nbsp;<input style="width:20%" id="kd_pos" type="text" name="kd_pos"  readonly value="<?php echo set_value('kd_pos'); ?>"  />
        </td>
        <td>&nbsp;</td>
        <td colspan="4"><label for="tgl_jatuh_pembayaran">Tgl Jatuh Tempo Pembayaran</label>&nbsp;
            <input style="width:150px"  class="date-picker" id="tgl_jatuh_pembayaran" type="text" name="tgl_jatuh_pembayaran" data-date-format="dd-mm-yyyy" value="<?php echo $tgl; ?>" />      
            <span class="required" style="color:#F00">*</span>	
        </td>
      </tr>
      <tr>
        <td width="140"><label for="no_telp">No. Telp</label></td>
        <td >
            <input  style="width:35%" id="no_telp" type="tel" name="no_telp" readonly  value="<?php echo set_value('no_telp'); ?>"  />&nbsp;&nbsp;
            <label for="no_fax">No. Fax</label>&nbsp;&nbsp;<input style="width:35%" id="no_fax" type="text" name="no_fax" readonly  value="<?php echo set_value('no_fax'); ?>"  />
        </td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td colspan="3">&nbsp;</td>
      </tr>
      <tr>
        <td>
            <p><br>
              <input type="button" name="bo_po" id="bo_po" value="Buat Produk Baru">
            </p>	
        </td>
        <td>&nbsp;</td>
        <td colspan="4"><br>
            <input style="margin-left:92%" type="button" name="bo_tambah" id="bo_tambah" onClick="addRow('table_po')" value="Insert Data Produk">
        </td>
        <td>&nbsp;</td>
      </tr>
    </table>
    
    <table width="100%" border="0px"> <!--Tabele Penampung Tabel No Format-->
      <tr height="auto">
        <td width="90%" rowspan="2">        
            <!--Tabel Purchasing Order-->
            <table width="100%" border="1px" id="" class="table table-striped table-bordered table-hover">
            <thead align="center">
              <tr>
                <td class="center"  style="background-color:#999; color:#FFF"></td> 
                <td width="auto"  	style="background-color:#999; color:#FFF">Kode</td>
                <td width="auto"	style="background-color:#999; color:#FFF">Nama Produk</td>
                <td width="auto"	style="background-color:#999; color:#FFF">Satuan</td>
                <td width="auto"	style="background-color:#999; color:#FFF">Harga</td>
                <td width="auto"	style="background-color:#999; color:#FFF">Qty</td>
                <td width="auto"	style="background-color:#999; color:#FFF">Diskon(%)</td>
                <td width="auto"	style="background-color:#999; color:#FFF">Total</td>
                <td width="auto"	style="background-color:#999; color:#FFF">Action</td>
              </thead>
              </tr>  
              <tbody id="table_po"><!--Data PO-->
              <tr>
                <td class="center"><INPUT type="checkbox" name="chk"/></td>            
                <td >
                    <input class="input-mini" id="kd_produk" type="text" name="kd_produk" value="<?php $prod ?>" readonly/>           
                </td> <!--Kode-->
                <td >                   
                <input type="text"  class="input-xlarge" name="nama_prd" id="nama_prd" placeholder="Pilih Produk" value="<?php echo $prod?>"/>	
                </td> <!--Nama Produk-->
               
                <td>            	
                    <input id="satuan" class="input-small" type="text" name="satuan" readonly />		
                </td> <!--Satuan-->
                <td>
                    <input style="text-align:right" class="input-large" id="harga" type="number" name="harga" readonly/>		            
                </td> <!--Harga-->
                <td>
                    <input style="text-align:right" class="input-small" id="qty" type="number" name="qty" />		                        
                </td> <!--Qty-->
                <td>
                    <input style="text-align:right;" class="input-mini" id="diskon" type="number" name="diskon" readonly/>		                        
                </td> <!--Diskon-->
                <td>
                    <input style="text-align:right;" class="input-large" id="total" type="number" name="total" readonly/>		                        
                </td> <!--Total-->
                <td class="center">
                
                <div class="hidden-phone visible-desktop action-buttons">                
                <a class="red" onClick="deleteRow('table_po')">
                    <i class="icon-trash bigger-130"></i>
                </a>                
                </div>                
                
                </td> <!--Hapus-->
              </tr>
              </tbody>
              
            </table> <!--End Of Table PO-->
            
        </td>
        
        <td align="center" height="20px" width="5%"> <!--Tombol Submit-->
            <input type="submit" name="simpan" value="Simpan" class="" />
        </td>      
      
      </tr>
      
      <tr height="auto">
        <td></td>
      </tr>
    
    </table>
    
    <label for="ket">Keterangan</label>
    <input style="width:87.4%" id="ket" type="text" name="ket"  value="<?php echo set_value('ket'); ?>"  />
            
    <!--Tabel Total Transaksi-->
    <table width="99%" border="0" style="margin:10px 0px">
      <tr>
        <td width="211">&nbsp;</td>
        <td width="160">&nbsp;</td>
        <td width="211">&nbsp;</td>
        <td style="text-align:right" colspan="2"><label for="kena_ppn">&nbsp;</label>
        Produk Sudah Kena PPn&nbsp</td>
        <td width="154">&nbsp
            <input id="kena_ppn" name="kena_ppn" type="radio" class="" value="1" checked="true" <?php echo $kena_ppn; ?> />
            <label for="kena_ppn" class="">Belum</label>
    
            <input id="kena_ppn" name="kena_ppn" type="radio" class="" value="2" <?php echo $kena_ppn; ?> />
            <label for="kena_ppn" class="">Sudah</label>
          <br></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td colspan="2">&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>Total Purchasing Order</td>
        <td><input style="text-align:right" 	id="total_po" type="text" name="total_po"  value="<?php echo $tot_po; ?>"  /></td>
        <td width="86"><label for="diskon_rp">&nbsp;&nbsp;Diskon (Rp)</label></td>
        <td colspan="2"><input style="text-align:right" id="diskon_rp" type="text" name="diskon_rp"  value="<?php echo $disc_rp; ?>"  /></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>Netto</td>
        <td><input style="text-align:right" id="netto" type="text" name="netto"  value="<?php echo $netto ; ?>"  /></td>
        <td><label for="diskon_prsn">&nbsp;&nbsp;Diskon (%)</label></td>
        <td colspan="2"><input style="text-align:right" id="diskon_prsn" type="text" name="diskon_prsn"  value="<?php echo $disc; ?>"  /></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>Netto + PPn</td>
        <td><input style="text-align:right" id="netto_ppn" type="text" name="netto_ppn"  value="<?php echo set_value('netto_ppn'); ?>"  /></td>
        <td>&nbsp;</td>
        <td width="182">&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
    </table>
    </div>        
    </div>
</div>

<?php echo form_close(); ?>
<?php $this->load->view("vfooter") ?>


<script src="<?php echo base_url(); ?>assets/js/bootstrap.min.js"></script>
<!--basic scripts-->
<script src="<?php echo base_url(); ?>assets/js/chosen.jquery.min.js"></script>
<script src="<?php echo base_url(); ?>assets/js/jquery-ui-1.10.3.custom.min.js"></script>

<!--page specific plugin scripts-->
<script src="<?php echo base_url(); ?>assets/js/jquery.dataTables.min.js"></script>
<script src="<?php echo base_url(); ?>assets/js/jquery.dataTables.bootstrap.js"></script>

<script src="<?php echo base_url(); ?>assets/js/date-time/bootstrap-datepicker.min.js"></script>
<!--End basic scripts-->

    <script src="<?php echo base_url()?>assets/jqueryui/ui/jquery.ui.core.js"></script>
    <script src="<?php echo base_url()?>assets/jqueryui/ui/jquery.ui.widget.js"></script>
    <script src="<?php echo base_url()?>assets/jqueryui/ui/jquery.ui.position.js"></script>
    <script src="<?php echo base_url()?>assets/jqueryui/ui/jquery.ui.menu.js"></script>
    <script src="<?php echo base_url()?>assets/jqueryui/ui/jquery.ui.autocomplete.js"></script>
   	<script src="<?php echo base_url()?>assets/jqueryui/ui/jquery.ui.tooltip.js"></script>

<!--inline scripts related to this page-->
<script language='javascript'>	
var site = "<?php echo site_url();?>";
$(function() {
	$("#nama_supplier").autocomplete({
	source: site+"/transaksi/search/supplier",	
	minLength: 1,
	select: function(event, ui) {
		var hasil = ui.item.value.split('-');
		$('#supplier_id').val(hasil[0]);
		$('#nama_supplier').val(hasil[1]);
		$('#alamat').val(hasil[2]);
		$('#kota').val(hasil[3]);
		$('#kd_pos').val(hasil[4]);
		$('#no_telp').val(hasil[5]);
		$('#no_fax').val(hasil[6]);				
		$('#email').val(hasil[7]);						
		$('#web').val(hasil[8]);						
		return false;
	}
	});	
});
							
var site = "<?php echo site_url();?>";
$(function() {
	$("#nama_prd").autocomplete({
	source: site+"/transaksi/search/barang",	
	minLength: 1,
	select: function(event, ui) {
		var hasil = ui.item.value.split('-');
		$('#kd_produk').val(hasil[0]);
		$('#nama_prd').val(hasil[1]);
		$('#qty').val('1');
		$('#harga').val(hasil[2]);
		$('#satuan').val(hasil[3]);
		$('#total').val(hasil[2]*1);
		return false;
	}
	});
	
});



/*ga jadi
function getData(dropdown)
{
 	var value = dropdown.options[dropdown.selectedIndex].value;
    alert(value);
	
//	document.form_po.alamat.value   = value;
	
	
}
*/

function addRow(tableID) {

	var table = document.getElementById(tableID);

	var rowCount = table.rows.length;
	var row = table.insertRow(rowCount);

	var colCount = table.rows[0].cells.length;

	for(var i=0; i<colCount; i++) {

		var newcell = row.insertCell(i);

		newcell.innerHTML = table.rows[0].cells[i].innerHTML;
		//alert(newcell.childNodes);
		switch(newcell.childNodes[0].type) {
			case "text":
					newcell.childNodes[0].value = "";
					break;
			case "checkbox":
					newcell.childNodes[0].checked = false;
					break;
			case "select-one":
					newcell.childNodes[0].selectedIndex = 0;
					break;
			case "input":
					newcell.childNodes[0].value = "";
					break;					
		}
	}
}

function deleteRow(tableID) {
	try {
	var table = document.getElementById(tableID);
	var rowCount = table.rows.length;

	for(var i=0; i<rowCount; i++) {
		var row = table.rows[i];
		var chkbox = row.cells[0].childNodes[0];
		if(null != chkbox && true == chkbox.checked) {
			if(rowCount <= 1) {
				alert("Cannot delete all the rows.");
				break;
			}
			table.deleteRow(i);
			rowCount--;
			i--;
		}


	}
	}catch(e) {
		alert(e);
	}
}

$(function() {	
	
		var oTable1 = $('#sample-table-2').dataTable( {
		"aoColumns": [
		  { "bSortable": false },
		  null, null,null, null, null,
		  { "bSortable": false }
		] } );
		
		
		$('table th input:checkbox').on('click' , function(){
			var that = this;
			$(this).closest('table').find('tr > td:first-child input:checkbox')
			.each(function(){
				this.checked = that.checked;
				$(this).closest('tr').toggleClass('selected');
			});
				
		});
				

		$('#id-disable-check').on('click', function() {
			var inp = $('#form-input-readonly').get(0);
			if(inp.hasAttribute('disabled')) {
				inp.setAttribute('readonly' , 'true');
				inp.removeAttribute('disabled');
				inp.value="This text field is readonly!";
			}
			else {
				inp.setAttribute('disabled' , 'disabled');
				inp.removeAttribute('readonly');
				inp.value="This text field is disabled!";
			}
		});					
	
	
		$(".chzn-select").chosen(); 
		
		$('.date-picker').datepicker().next().on(ace.click_event, function(){
			$(this).prev().focus();
		});
									
		$.mask.definitions['~']='[+-]';
		$('.input-mask-date').mask('99/99/9999');
		$('.input-mask-phone').mask('(999) 999-9999');
		$('.input-mask-eyescript').mask('~9.99 ~9.99 999');
		$(".input-mask-product").mask("a*-999-a999",{placeholder:" ",completed:function(){alert("You typed the following: "+this.val());}});

	
		
});
		

</script>			
<!--End inline scripts related to this page-->

</body>
</html>
